package com.shengruan.common;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import com.shengruan.admin.vo.User;

public class OnlineCounterListener implements HttpSessionListener { 
    public void sessionCreated(HttpSessionEvent hse) { 
    	Visitor onUser = new Visitor();
    	onUser.setCtime(System.currentTimeMillis());
    	onUser.setCometime(Function.getDetailDate());
    	onUser.setUsername("游客");
        OnlineCounter.addUser(onUser); 
        HttpSession httpSession = hse.getSession();
        httpSession.setAttribute("onLineUser", onUser);
        httpSession.setMaxInactiveInterval(60*20);
       
    } 
    public void sessionDestroyed(HttpSessionEvent hse) { 
    	
    	HttpSession httpSession = hse.getSession();
    	Visitor onUser = (Visitor)httpSession.getAttribute("onLineUser");
        OnlineCounter.removeUser(onUser); 
        User user = (User)httpSession.getAttribute("user");
		OnLineUser.removeUser(user);
       
    } 
} 